package com.atguigu.gmall.mq.controller;

import com.atguigu.gmall.common.service.RabbitService;
import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import com.atguigu.gmall.mq.config.DelayMqConfig;
import com.atguigu.gmall.product.client.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/mq")
public class MqSendController {

    @Autowired
    private RabbitService rabbitService;
        //发送消息
    @GetMapping("/sendMessage")
    public Result sendMessage1(String message){

        rabbitService.sendMessage(
                "exchange111",  //交换机
                "routingKey",  //路由Key
                message);   //发送的消息
        return Result.ok();
    }
    //发送消息
    @GetMapping("/sendMessage2")
    public Result sendMessage2(String message){

        rabbitService.sendMessage(
                "exchange222",  //交换机
                "routingKey222",  //路由Key
                message);   //发送的消息
        return Result.ok();
    }

    //发死信消息  （基于死信）
    @GetMapping("/sendDeadLetterMessage")
    public Result sendDeadLetterMessage(String message){

        rabbitService.sendDeadLetterMessage(DeadLetterMqConfig.exchange_dead,
                DeadLetterMqConfig.routing_dead_1,message,7);

        return Result.ok();
    }

    //发延迟消息
    @GetMapping("/sendDelayMessage")
    public Result sendDelayMessage(String message){
        rabbitService.sendDelayMessage(
                DelayMqConfig.exchange_delay, //绑定完成的交换机
                DelayMqConfig.routing_delay,  //绑定完成的routingKey
                message,  //发送的消息
                9   //延迟消息的时间
        );
        return Result.ok();
    }


}
